package cn.bdqn.layui.service.rabbit;

import cn.bdqn.layui.entity.ProductSuccess;
import cn.bdqn.layui.mapper.ProductSuccessMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时任务
 */
@Service
public class SchedulerService {


    @Resource
    ProductSuccessMapper productSuccessMapper;

    /**
     * 定时获取订单是否超过时间 超过失效
     */
    @Scheduled(cron = "0 0/30 * * * ? ")
    public void schedulerExpireOrders(){
        List<ProductSuccess> productSuccesses = productSuccessMapper.selectExpireOrders();
        if (productSuccesses != null) {
            for (ProductSuccess success : productSuccesses){
                if(success != null && success.getDiffTime()>30){
                    //失效订单
                    productSuccessMapper.expireOrder(success.getCode());
                }
            }
        }
    }
}
